%% Replication code for "Don't Call It a Comeback: Autocratic Ruling Parties after Democratization," by Michael K. Miller, in British Journal of Political Science
%% Prepared December 19, 2018


% Tables

% Main prediction of party success (Table 2)

global party "asp_party_violentend asp_party_age asp_party_yrsinpower asp_party_avgpartybarr asp_party_avggrowth asp_party_terrloss"
global party2 ""
global base "loggdp growth2 regionbmr2 bmr2_age bmr2_prevauth year postcoldwar"
global cond "if asp_marker_partydem==1"
global se "r cluster(elecperiodid)"
global heckbase "loggdp growth2 regionbmr2 bmr2_age bmr2_prevauth year postcoldwar regionea Britcolony nocolony literacy"
global heckse "cluster elecperiodid"
global heckcond "if year >= 1940 & year <= 2015"

eststo clear
global dv "asp_party_compet_altered"
eststo: quietly logit $dv $party $party2 $base $cond, $se
global dv "asp_party_power_altered"
eststo: quietly logit $dv $party $party2 $base $cond, $se
global dv "asp_party_rcp_altered"
eststo: quietly ologit $dv $party $party2 $base $cond, $se
global dv "asp_party_compet_altered"
eststo: quietly heckprob $dv $party $party2 $base $heckcond, select(asp_heckman_partydem = $heckbase) vce($heckse)
global dv "asp_party_power_altered"
eststo: quietly heckprob $dv $party $party2 $base $heckcond, select(asp_heckman_partydem = $heckbase) vce($heckse)
global dv "asp_party_rcp_altered"
eststo: quietly heckman $dv $party $party2 $base $heckcond, select(asp_heckman_partydem = $heckbase) vce($heckse)
esttab, pr2


% Additional variables (Tables 3-4) [uses model variation in Table 2]

global party2 "asp_party_policy asp_party_client"
global party2 "asp_party_ethnic"
global party2 "asp_party_marxist"
global party2 "asp_party_pureparty asp_party_militaryhybrid"
tab asp_party_origin, gen(d_asp_party_origin)
global party2 "d_asp_party_origin2 d_asp_party_origin4 d_asp_party_origin8"
global party2 "asp_party_avgrepress"
global party2 "asp_party_avgcorrupt"
global party2 "asp_party_avgequalres"

global party2 "vdem_pr"
global party2 "dpi_thresh"
global party2 "vdem_compulsory"
global party2 "federal"
global party2 "vdem_constraint courtpower"
global party2 "vdem_civilsoc"
global party2 "growth_demvsauth"

esttab, pr2 keep($party2)



% Robustness checks

% Regime type controls (Table A2)

global party2 "asp_party_pureparty"
global party2 "asp_party_pureparty asp_party_partyhybrid"
global party2 "asp_party_pureparty asp_party_militaryhybrid"
global party2 "asp_party_pureparty asp_party_puremilitary"
global party2 "asp_party_pureparty asp_party_pershybrid"
global party2 "asp_party_pureparty asp_party_purepers"
esttab, pr2 keep($party2)

% Regime type stratified models (Table A3)

global party2 ""
global dv "asp_party_rcp_altered"
version 10: eststo: quietly ologit $dv $party $party2 $base $cond & asp_party_pureparty==1, $se
version 10: eststo: quietly ologit $dv $party $party2 $base $cond & asp_party_pureparty==0, $se
version 10: eststo: quietly ologit $dv $party $party2 $base $cond & asp_party_militaryhybrid==1, $se
version 10: eststo: quietly ologit $dv $party $party2 $base $cond & asp_party_pershybrid==1, $se
esttab, pr2

% Various checks (Table A4)

global dv "asp_party_rcp_altered"
version 10: eststo: quietly ologit $dv asp_party_powergapdemz $party $party2 $base $cond, $se
global cond "if asp_marker_partydem==1 & (vdem_legelection==1 | vdem_execelection==1)"
global cond "if asp_marker_partydem==1 & asp_party_yrsinpower >= 5"
global cond "if asp_marker_partydem==1 & bmr2_age <= 10"
global cond "if asp_marker_partydem==1 & asp_party_violentend==0"
global cond "if asp_marker_partydem==1 & asp_party_violentend==1"
version 10: eststo: quietly ologit $dv $party $party2 $base $cond, $se
esttab, pr2

% Alternative democracy measures (Table A5)

global dv "asp_party_rcp_altered"
eststo: quietly ologit $dv $party $party2 $base $cond, $se
eststo: quietly ologit $dv $party $party2 $base $cond & polity2 >= 6, $se
eststo: quietly ologit $dv $party $party2 $base $cond & fh_pr <= 3 & fh_cl <= 3, $se
eststo: quietly ologit $dv $party $party2 $base $cond & vdem_polyarchy >= 0.5, $se
esttab, pr2

% Checks mentioned in text

tab region, gen(d_region)
global base "loggdp growth2 regionbmr2 bmr2_age bmr2_prevauth year postcoldwar d_region2-d_region8"
tab year, gen(d_year)
global base "loggdp growth2 regionbmr2 bmr2_age bmr2_prevauth d_year2-d_year211"

global party2 "asp_party_ethnicmin"
global party2 "asp_party_ethnic ELF"
global party2 "asp_party_ruleatindy"
global party2 "literacy"
global party2 "vdem_educ"
global party2 "gini"
global party2 "youth age65"



% IV predicting democratic survival + quality (Table 5)

global party "asp_dict_power asp_party_anyauthspell"
global party2 ""
global base "growth_demvsauth vdem_xrepress_demvsauth vdem_equalres_demvsauth vdem_corrupt_demvsauth vdem_repress vdem_equalres vdem_corrupt asp_party_violentend loggdp growth2 regionbmr2 bmr2_age bmr2_prevauth year postcoldwar"
global iv "asp_party_avgequalres asp_party_avggrowth asp_party_avgcorrupt asp_party_avgrepress"
global cond "if bmr2==1 & asp_marker_alldem==1"
global se "r cluster(elecperiodid)"

eststo clear
global dv2 "fbmr2"
eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_compet_a_lastparty = $iv) $cond, $se
eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_power_a_lastparty  = $iv) $cond, $se
eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_rcp_a_lastparty  = $iv) $cond, $se
global dv3 "vdem_liberal"
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base (asp_party_compet_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base (asp_party_power_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base (asp_party_rcp_a_lastparty = $iv) $cond, $se
esttab, pr2

% IV diagnostics (Table A6)
global dv2 "fbmr2"
eststo: ivprobit $dv2 $party $party2 $base (asp_party_compet_a_lastparty = $iv) $cond, $se first
eststo: ivprobit $dv2 $party $party2 $base (asp_party_power_a_lastparty  = $iv) $cond, $se first
eststo: ivprobit $dv2 $party $party2 $base (asp_party_rcp_a_lastparty  = $iv) $cond, $se first



% IV robustness checks (Table A7)

% Alt lags
global dv3 "vdem_liberal"
eststo clear
eststo: quietly ivreg2 F.$dv3 L.$dv3 $party $party2 $base (asp_party_compet_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L.$dv3 $party $party2 $base (asp_party_power_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L.$dv3 $party $party2 $base (asp_party_rcp_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L9.$dv3 $party $party2 $base (asp_party_compet_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L9.$dv3 $party $party2 $base (asp_party_power_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L9.$dv3 $party $party2 $base (asp_party_rcp_a_lastparty = $iv) $cond, $se
esttab, b(3) pr2

% Alternative democracy measures

global dv2 "fbmr2_addpolity"
global cond "if bmr2_addpolity==1 & asp_marker_alldem==1"
global dv2 "fbmr2_addfh"
global cond "if bmr2_addfh==1 & asp_marker_alldem==1"
global dv2 "fbmr2_addvdem"
global cond "if bmr2_addvdem==1 & asp_marker_alldem==1"

% Democracy age >= 5
global cond "if bmr2==1 & asp_marker_alldem==1 & bmr2_age >= 5"

% Election control
eststo clear
global elec "vdem_legelection vdem_execelection"
global dv2 "fbmr2"
eststo: quietly ivprobit $dv2 $party $party2 $base $elec (asp_party_compet_a_lastparty = $iv) $cond, $se
eststo: quietly ivprobit $dv2 $party $party2 $base $elec (asp_party_power_a_lastparty  = $iv) $cond, $se
eststo: quietly ivprobit $dv2 $party $party2 $base $elec (asp_party_rcp_a_lastparty  = $iv) $cond, $se
global dv3 "vdem_liberal"
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base $elec (asp_party_compet_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base $elec (asp_party_power_a_lastparty = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base $elec (asp_party_rcp_a_lastparty = $iv) $cond, $se
esttab, b(3) pr2

% Only most recent party
eststo clear
global dv2 "fbmr2"
eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_compet_altered = $iv) $cond, $se
eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_power_altered  = $iv) $cond , $se
eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_rcp_altered  = $iv) $cond, $se
global dv3 "vdem_liberal"
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base (asp_party_compet_altered = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base (asp_party_power_altered = $iv) $cond, $se
eststo: quietly ivreg2 F.$dv3 L4.$dv3 $party $party2 $base (asp_party_rcp_altered = $iv) $cond, $se
esttab, b(3) pr2

% Full democracy sample
global cond "if bmr2==1 & asp_marker_alldem==1"
global iv "asp_party_avgequalresx asp_party_avggrowthx asp_party_avgcorruptx asp_party_avgrepressx"
global base "vdem_equalres vdem_repress vdem_corrupt asp_party_violentendx loggdp growth2 regionbmr2 bmr2_age bmr2_prevauth year postcoldwar"
global party "asp_dict_power asp_party_anyauthspell"
global party2 ""
global se "r cluster(elecperiod)"
global dv2 "fbmr2"
eststo clear
version 10: eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_compet_a_lastparty = $iv) $cond, $se
version 10: eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_power_a_lastparty  = $iv) $cond, $se
version 10: eststo: quietly ivprobit $dv2 $party $party2 $base (asp_party_rcp_a_lastparty  = $iv) $cond, $se
global dv3 "vdem_liberal"
version 10: eststo: quietly ivreg2 $dv3 L5.$dv3 $party $party2 $base (asp_party_compet_a_lastparty = $iv) $cond, $se
version 10: eststo: quietly ivreg2 $dv3 L5.$dv3 $party $party2 $base (asp_party_power_a_lastparty = $iv) $cond, $se
version 10: eststo: quietly ivreg2 $dv3 L5.$dv3 $party $party2 $base (asp_party_rcp_a_lastparty = $iv) $cond, $se
esttab, pr2



% Figures

% Figure 1

set scheme s1color
tw line asp_year_competavg2 year if year >= 1946 || line asp_year_poweravg2 year if year >= 1946

% Figure 2

set scheme s1color
global party "asp_party_violentend asp_party_age asp_party_yrsinpower asp_party_avgpartybarr asp_party_avggrowth asp_party_terrloss"
global base "loggdp growth2 regionbmr2 bmr2_age bmr2_prevauth year postcoldwar"
global cond "if asp_marker_partydem==1"
global se "r cluster(elecperiodid)"
global dv "asp_party_compet_altered"
global party2 ""
global party2 "asp_party_policy asp_party_client"
global party2 "asp_party_pureparty"
global party2 "d_asp_party_origin2 d_asp_party_origin4 d_asp_party_origin8"
global party2 ""
global party2 "vdem_pr"
quietly logit $dv $party $party2 $base $cond, $se

margins, at(asp_party_violentend=(0(1)1)) vsquish atmeans
marginsplot, recast(scatter) recastci(rspike) yline(0)
margins, at(asp_party_policy=0 asp_party_client=1) at(asp_party_policy=1 asp_party_client=0) vsquish atmeans
marginsplot, recast(scatter) recastci(rspike) yline(0)
margins, at(asp_party_pureparty=(0(1)1)) vsquish atmeans
marginsplot, recast(scatter) recastci(rspike) yline(0)
margins, at(d_asp_party_origin2=0) at(d_asp_party_origin2=1 d_asp_party_origin4=0 d_asp_party_origin8=0) vsquish atmeans
marginsplot, recast(scatter) recastci(rspike) yline(0)
margins, at(asp_party_avggrowth=(-5.5(.2)6.5)) vsquish atmeans
marginsplot, recast(scatter) recastci(rspike) yline(0)
margins, at(vdem_pr=(0(1)1)) vsquish atmeans
marginsplot, recast(scatter) recastci(rspike) yline(0)

